package com.yz.platform.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * author:lin Date : 2017/8/30 上午11:58
 */
public class RegexUtils {

    /**
     * 匹配字符串
     * @param pattern
     * @param str
     * @return
     */
    public static List<String> matchString(Pattern pattern, String str) {

        List<String> result = new ArrayList<String>();
        Matcher mc = pattern.matcher(str);

        while (mc.find()) {
            result.add(mc.group());
        }

        return result;
    }


    /**
     * 匹配数字
     * @param pattern
     * @param str
     * @return
     */
    public static List<Integer> matchInteger(Pattern pattern, String str) {
        List<Integer> result = new ArrayList<Integer>();
        Matcher mc = pattern.matcher(str);

        while (mc.find()) {
            result.add(new Integer(mc.group().trim()));
        }

        return result;
    }
}
